local skel = fk.CreateSkill {
  name = "emo__zhishui",
}

Fk:loadTranslationTable{
  ["emo__zhishui"] = "止水",
  [":emo__zhishui"] = "每轮开始时，你可以弃置X张牌并选择一名角色，其本轮受到的首次伤害和大于1点的伤害-1（X为本技能发动次数）。",

  ["#emo__zhishui-choose"] = "止水：你可弃%arg张牌并选择一名角色，其本轮受到的首次伤害和大于1点的伤害-1",
  ["@@emo__zhishui-round"] = "止水",
}

skel:addEffect(fk.RoundStart, {
  anim_type = "support",
  can_trigger = function(self, event, target, player, data)
    return player:hasSkill(skel.name)
  end,
  on_cost = function(self, event, target, player, data)
    local room = player.room
    local x = player:usedSkillTimes(skel.name, Player.HistoryGame) + 1
    local tos, cards = room:askToChooseCardsAndPlayers(player, {
      min_card_num = x, max_card_num = x, min_num = 1, max_num = 1, skill_name = skel.name,
      will_throw = true, targets = room.alive_players,
      prompt = "#emo__zhishui-choose:::" .. x,
    })
    if #tos > 0 and #cards == x then
      event:setCostData(self, {tos = tos, cards = cards})
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local to = event:getCostData(self).tos[1]
    room:throwCard(event:getCostData(self).cards, skel.name, player, player)
    if to.dead then return end
    room:addPlayerMark(to, "@@emo__zhishui-round")
  end,
})

skel:addEffect(fk.DamageInflicted, {
  anim_type = "defensive",
  is_delay_effect = true,
  can_trigger = function(self, event, target, player, data)
    return target:getMark("@@emo__zhishui-round") > 0 and player == target
    and (data.damage > 1 or player:getMark("emo__zhishui_invoked-round") == 0)
  end,
  on_cost = Util.TrueFunc,
  on_use = function(self, event, target, player, data)
    local room = player.room
    if data.damage > 1 then
      data:changeDamage(-1)
    end
    if player:getMark("emo__zhishui_invoked-round") == 0 then
      room:setPlayerMark(player, "emo__zhishui_invoked-round", 1)
      data:changeDamage(-1)
    end
  end,
})

return skel
